﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace AutoUpgradeManager.ControlForm
{
    /// <summary>
    /// Window_PrjVersionSetup.xaml 的交互逻辑
    /// </summary>
    public partial class Window_PrjVersionSetup : Window
    {
        /// <summary>
        /// 项目版本
        /// </summary>
        public string PrjVersion
        {
            get;
            private set;
        }
        /// <summary>
        /// 项目时间
        /// </summary>
        public string PrjDataTime
        {
            get;
            private set;
        }
        /// <summary>
        /// 项目启动程序
        /// </summary>
        public string StartProgram
        {
            get;
            private set;
        }

        public void SetStartProgramList(IEnumerable<string> FileList)
        { 
            foreach(string s in FileList)
            {
                Cmb_StartProgram.Items.Add(s);
            }
        
        }


        public Window_PrjVersionSetup()
        {
            InitializeComponent();
            Txt_DateTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        }

        private void Btn_Close_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
            this.Close();
        }

        private void Btn_Ok_Click(object sender, RoutedEventArgs e)
        {
            PrjVersion = Txt_Version.Text;
            PrjDataTime = Txt_DateTime.Text;

            StartProgram = Cmb_StartProgram.Text;

            string[] tmparr = PrjVersion.Split('.');

            if (tmparr.Length != 3 )
            {
                MessageBox.Show("项目版本号输入格式错误，正确格式为：N.N.N，其中N为数字", "输入验证", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }
            else
            {
                foreach (string s in tmparr)
                {
                    int i;
                    if (!int.TryParse(s, out i))
                    {
                        MessageBox.Show("项目版本号输入格式错误，正确格式为：N.N.N，其中N为数字", "输入验证", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        return;
                    }
                }
            }
            
            this.DialogResult = true;
            
            this.Close();
        }
        /// <summary>
        /// 文本框回车消息处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Txt_Version_PreviewKeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter && Txt_Version.Text.Trim() != "")
            {
                Btn_Ok_Click(Btn_Ok, new RoutedEventArgs());
            }
            e.Handled = true;
        }

    }
}
